<template>
    <div>
        <div :class="item.className">
            <span class="user-img">
                <img :src="`../../static/img/0${userImgIndex%10+1}.gif`" />
            </span>
            <div class="message-content">
                <div style="font-weight: bold" :style="{color: themeColor}" v-if="/groupChat/.test(item.to || item.from)">{{item.from.replace('groupChat_','')}}</div>
                <div v-html="item.msg"></div>
            </div>
        </div>
<!--        <p v-else class="prompt" v-html="item.msg"></p>-->
    </div>
</template>

<script>
import {mapGetters} from 'vuex'
import concat from "lodash/concat";
export default {
    props:["item"],
    name: "chat-item",
    computed:{
        ...mapGetters([
            'themeColor',
            'userList'
        ]),
        userImgIndex(){
            return this.userList.findIndex(i=>(this.item.from || this.item.to).includes(i))
        },
    },
    methods:{

    },
    created() {

    }
}
</script>

<style scoped lang="scss">
    .prompt{
        text-align: center;
        margin: 15px 0;
    }
    .prompt {
        >>> span {
            padding: 5px 10px;
            font-size: 12px;
            border-radius: 6px;
            border: 1px solid rgba(0,0,0,0.3);
            color: #FFF;
            background-color: rgba(0,0,0,0.5);
        }
    }
    .message-right .user-img{
        left: auto;
        right: 0;
    }
    .message-left .user-img{
        left: 0;
        right: auto;
    }
    .message-left .message-content{
        margin-left: 55px;
        background-color: #dfeffe;
        &:after {
            left: -13px;
            background-position: -3px -2px;
        }
    }
    .message-right .message-content{
        margin-right: 55px;
        float: right;
        background-color: #e0f3e0;
        &:after {
            left: auto;
            right: -14px;
            background-position: -60px -2px;
        }
    }
    .message-left ,.message-right{
        width: 100%;
        padding: 10px 0;
        min-height: 50px;
        overflow: hidden;
        position: relative;
        .user-img {
            width: 40px;
            height: 40px;
            display: block;
            position: absolute;
            top: 10px;
            img {
                width: 40px;
                height: 40px;
                border-radius: 40px;
            }
        }
        .message-content {
            box-sizing: border-box;
            word-break: break-all;
            min-width: 40px;
            max-width: 80%;
            min-height: 40px;
            display: inline-block;
            border-radius: 6px;
            border: 1px solid rgba(0,0,0,0.2);
            padding: 10px;
            font-size: 14px;
            color: #333;
            position: relative;
            margin-left:55px;
            -webkit-user-select: initial;
            >>> img {
                max-width: 100%;
            }
            &:after {
                content: '';
                width: 20px;
                height: 20px;
                display: block;
                position: absolute;
                top: 10px;
                background-image: url(../../static/img/arrow.png);
                background-repeat: no-repeat;
            }
        }
    }
</style>
